linux: Introduce {current_,}vcpu_info.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 19 Feb 2007 16:11:56 +0000 (16:11 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 19 Feb 2007 16:11:56 +0000 (16:11 +0000)
Also consolidate time-xen.c in giving get_time_values_from_xen() a
'cpu' parameter to match other functions (this consolidation could of
course also be done the other way around, but I think this way the
resulting code can be more efficient).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c
linux-2.6-xen-sparse/arch/x86_64/mm/fault-xen.c
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/irqflags.h
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/irqflags.h

index 7c0c2984fa7dcc763afbdc1c04ab56a5263a74cf..9dc489b404d4659ac1f918692f313ae0af45bb49 100644 (file)
@@ -222,8 +222,7 @@ int read_current_timer(unsigned long *timer_val)
 void init_cpu_khz(void)
 {
        u64 __cpu_khz = 1000000ULL << 32;
-       struct vcpu_time_info *info;
-       info = &HYPERVISOR_shared_info->vcpu_info[0].time;
+       struct vcpu_time_info *info = &vcpu_info(0)->time;
        do_div(__cpu_khz, info->tsc_to_system_mul);
        if (info->tsc_shift < 0)
                cpu_khz = __cpu_khz << -info->tsc_shift;
@@ -293,14 +292,13 @@ static void update_wallclock(void)
  * Reads a consistent set of time-base values from Xen, into a shadow data
  * area.
  */
-static void get_time_values_from_xen(void)
+static void get_time_values_from_xen(int cpu)
 {
-       shared_info_t           *s = HYPERVISOR_shared_info;
        struct vcpu_time_info   *src;
        struct shadow_time_info *dst;
 
-       src = &s->vcpu_info[smp_processor_id()].time;
-       dst = &per_cpu(shadow_time, smp_processor_id());
+       src = &vcpu_info(cpu)->time;
+       dst = &per_cpu(shadow_time, cpu);
 
        do {
                dst->version = src->version;
@@ -320,7 +318,7 @@ static inline int time_values_up_to_date(int cpu)
        struct vcpu_time_info   *src;
        struct shadow_time_info *dst;
 
-       src = &HYPERVISOR_shared_info->vcpu_info[cpu].time;
+       src = &vcpu_info(cpu)->time;
        dst = &per_cpu(shadow_time, cpu);
 
        rmb();
@@ -412,7 +410,7 @@ void do_gettimeofday(struct timeval *tv)
                         * overflowed). Detect that and recalculate
                         * with fresh values.
                         */
-                       get_time_values_from_xen();
+                       get_time_values_from_xen(cpu);
                        continue;
                }
        } while (read_seqretry(&xtime_lock, seq) ||
@@ -456,7 +454,7 @@ int do_settimeofday(struct timespec *tv)
                nsec = tv->tv_nsec - get_nsec_offset(shadow);
                if (time_values_up_to_date(cpu))
                        break;
-               get_time_values_from_xen();
+               get_time_values_from_xen(cpu);
        }
        sec = tv->tv_sec;
        __normalize_time(&sec, &nsec);
@@ -551,7 +549,7 @@ unsigned long long monotonic_clock(void)
                barrier();
                time = shadow->system_timestamp + get_nsec_offset(shadow);
                if (!time_values_up_to_date(cpu))
-                       get_time_values_from_xen();
+                       get_time_values_from_xen(cpu);
                barrier();
        } while (local_time_version != shadow->version);
 
@@ -621,7 +619,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        write_seqlock(&xtime_lock);
 
        do {
-               get_time_values_from_xen();
+               get_time_values_from_xen(cpu);
 
                /* Obtain a consistent snapshot of elapsed wallclock cycles. */
                delta = delta_cpu =
@@ -921,7 +919,7 @@ void __init time_init(void)
                return;
        }
 #endif
-       get_time_values_from_xen();
+       get_time_values_from_xen(0);
 
        processed_system_time = per_cpu(shadow_time, 0).system_timestamp;
        per_cpu(processed_system_time, 0) = processed_system_time;
@@ -1029,7 +1027,7 @@ void time_resume(void)
 {
        init_cpu_khz();
 
-       get_time_values_from_xen();
+       get_time_values_from_xen(0);
 
        processed_system_time = per_cpu(shadow_time, 0).system_timestamp;
        per_cpu(processed_system_time, 0) = processed_system_time;
index 7613a8aacefae98cb8022729f25c01944be226c9..5c832c8bebd750f0cf6524d12b6e2095baca6da4 100644 (file)
@@ -411,8 +411,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
        prefetchw(&mm->mmap_sem);
 
        /* get the address */
-       address = HYPERVISOR_shared_info->vcpu_info[
-               smp_processor_id()].arch.cr2;
+       address = current_vcpu_info()->arch.cr2;
 
        info.si_code = SEGV_MAPERR;
 
index f7904ac0b078d1289ffcfed9ccb96468919325e7..3b5256778cf327debbb9c5df6ae0fa081d882d07 100644 (file)
 #include <xen/interface/nmi.h>
 #include <asm/ptrace.h>
 #include <asm/page.h>
-#if defined(__i386__)
-#  ifdef CONFIG_X86_PAE
-#   include <asm-generic/pgtable-nopud.h>
-#  else
-#   include <asm-generic/pgtable-nopmd.h>
-#  endif
-#endif
 
 extern shared_info_t *HYPERVISOR_shared_info;
 
+#define vcpu_info(cpu) (HYPERVISOR_shared_info->vcpu_info + (cpu))
+#define current_vcpu_info() vcpu_info(smp_processor_id())
+
 #ifdef CONFIG_X86_32
 extern unsigned long hypervisor_virt_start;
 #endif
index 3ee313fb53dd6a33d382037a59ef48a8ec74184c..2a71405dbb883455f157a11e0671538b1593831f 100644 (file)
 
 #ifndef __ASSEMBLY__
 
-#ifdef CONFIG_SMP
-#define __vcpu_id smp_processor_id()
-#else
-#define __vcpu_id 0
-#endif
-
 /* 
  * The use of 'barrier' in the following reflects their use as local-lock
  * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
@@ -26,8 +20,7 @@
  * includes these barriers, for example.
  */
 
-#define __raw_local_save_flags()                                       \
-       (&HYPERVISOR_shared_info->vcpu_info[__vcpu_id])->evtchn_upcall_mask;
+#define __raw_local_save_flags() (current_vcpu_info()->evtchn_upcall_mask)
 
 #define raw_local_save_flags(flags) \
                do { (flags) = __raw_local_save_flags(); } while (0)
@@ -36,7 +29,7 @@
 do {                                                                   \
        vcpu_info_t *_vcpu;                                             \
        barrier();                                                      \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
+       _vcpu = current_vcpu_info();                                    \
        if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {                   \
                barrier(); /* unmask then check (avoid races) */        \
                if (unlikely(_vcpu->evtchn_upcall_pending))             \
@@ -46,9 +39,7 @@ do {                                                                  \
 
 #define raw_local_irq_disable()                                                \
 do {                                                                   \
-       vcpu_info_t *_vcpu;                                             \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
-       _vcpu->evtchn_upcall_mask = 1;                                  \
+       current_vcpu_info()->evtchn_upcall_mask = 1;                    \
        barrier();                                                      \
 } while (0)
 
@@ -56,7 +47,7 @@ do {                                                                  \
 do {                                                                   \
        vcpu_info_t *_vcpu;                                             \
        barrier();                                                      \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
+       _vcpu = current_vcpu_info();                                    \
        _vcpu->evtchn_upcall_mask = 0;                                  \
        barrier(); /* unmask then check (avoid races) */                \
        if (unlikely(_vcpu->evtchn_upcall_pending))                     \
index 56bbb6b49403949169ca3fca83d5a843ba3a4a6f..55b227aa595d721df6e8228a53ba19cb964a1bda 100644 (file)
@@ -100,8 +100,7 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
 #define write_cr0(x) \
        __asm__ __volatile__("movl %0,%%cr0": :"r" (x))
 
-#define read_cr2() \
-       (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
+#define read_cr2() (current_vcpu_info()->arch.cr2)
 #define write_cr2(x) \
        __asm__ __volatile__("movl %0,%%cr2": :"r" (x))
 
index 154faffb02bd688a3fb19132b99757ee1d627123..45dff0f45a29653aeb3b235f6bad1098871a6a27 100644 (file)
  * Interrupt control:
  */
 
-#ifdef CONFIG_SMP
-#define __vcpu_id smp_processor_id()
-#else
-#define __vcpu_id 0
-#endif
-
 /*
  * The use of 'barrier' in the following reflects their use as local-lock
  * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
@@ -29,8 +23,7 @@
  * includes these barriers, for example.
  */
 
-#define __raw_local_save_flags()                                       \
-       (&HYPERVISOR_shared_info->vcpu_info[__vcpu_id])->evtchn_upcall_mask;
+#define __raw_local_save_flags() (current_vcpu_info()->evtchn_upcall_mask)
 
 #define raw_local_save_flags(flags) \
                do { (flags) = __raw_local_save_flags(); } while (0)
@@ -39,7 +32,7 @@
 do {                                                                   \
        vcpu_info_t *_vcpu;                                             \
        barrier();                                                      \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
+       _vcpu = current_vcpu_info();            \
        if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {                   \
                barrier(); /* unmask then check (avoid races) */        \
                if ( unlikely(_vcpu->evtchn_upcall_pending) )           \
@@ -76,9 +69,7 @@ static inline int raw_irqs_disabled_flags(unsigned long flags)
 
 #define raw_local_irq_disable()                                                \
 do {                                                                   \
-       vcpu_info_t *_vcpu;                                             \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
-       _vcpu->evtchn_upcall_mask = 1;                                  \
+       current_vcpu_info()->evtchn_upcall_mask = 1;                                    \
        barrier();                                                      \
 } while (0)
 
@@ -86,7 +77,7 @@ do {                                                                  \
 do {                                                                   \
        vcpu_info_t *_vcpu;                                             \
        barrier();                                                      \
-       _vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];          \
+       _vcpu = current_vcpu_info();            \
        _vcpu->evtchn_upcall_mask = 0;                                  \
        barrier(); /* unmask then check (avoid races) */                \
        if ( unlikely(_vcpu->evtchn_upcall_pending) )                   \